package com.huabo.contract.service.impl;


import cn.hutool.core.util.StrUtil;

import com.github.pagehelper.PageHelper;
import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.DateUtil;
import com.hbfk.util.FtpUtil;
import com.hbfk.util.JsonBean;
import com.hbfk.util.JudgeRoleRight;
import com.hbfk.util.PageInfo;
import com.hbfk.util.ResponseFormat;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.mysql.entity.TblCyhwUnitMySql;
import com.huabo.contract.oracle.entity.*;
import com.huabo.contract.oracle.mapper.*;
import com.huabo.contract.service.TblCirculationService;
import com.huabo.contract.service.TblCyhwUnitService;
import com.huabo.contract.util.DateUtils;
import com.huabo.contract.util.HttpClient;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

@Service
@Slf4j
public class TblCyhwUnitServiceImpl implements TblCyhwUnitService {

    @Resource
    private TblCyhwUnitMapper tblCyhwUnitMapper;

    @Resource
    private TblFlowMapper tblFlowMapper;
    @Resource
    private TblStaffMapper tblStaffMapper;

    @Resource
    private TblProcessAnalysisMapper tblProcessAnalysisMapper;

    @Resource
    private TblContractTypeofMapper tblContractTypeofMapper;

    @Resource
    private TblOrganizationMapper tblOrganizationMapper;

    @Resource
    private TblProcessAnalusisUserMapper tblProcessAnalusisUserMapper;

    @Resource
    private TblCirculationMapper tblCirculationMapper;

    @Resource
    private TblMyTaskMapper tblMytaskMapper;

    @Resource
    private TblContractPlannodeMapper tblContractPlannodeMapper;

    @Resource
    private TblCyhwProjectbudgetMapper tblCyhwProjectbudgetMapper;

    @Resource
    private TblContractPlannodeMapper  contractPlannodeMapper;

    @Resource
    private TblContractAppendixsigningMapper tblContractAppendixsigningMapper;

    @Resource
    private TblContractCollectionMapper tblContractCollectionMapper;
    @Resource
    private TblContractPaymentMapper tblContractPaymentMapper;

    @Resource
    private TblCyhwUnitService tblCyhwUnitService;

    @Resource
    private TblContractInformationMapper tblContractInformationMapper;

    @Resource
    private TblCirculationService tblCirculationService;
    
    @Resource
    private TblContractLendMapper tblContractLendMapper;



    @Override
    public Map<String, Object> findListContractBiangengBypageInfo(String token, String flowId, String staffId, Integer pageNumber, Integer pageSize, TblCyhwUnit cyhwUnit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                //Integer paCount = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(), staff);
                Integer paCount = 1;
                List<TblContractTypeof> typeList = this.tblContractTypeofMapper.findAllList(staff.getCurrentOrg().getOrgid(), -1);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                cyhwUnit.setFlowid(flow.getFlowid());
                cyhwUnit.setRecordtype(flow.getFlownumber());
                pageInfo.setCondition(cyhwUnit);

                if ("HTGL005".equals(flow.getFlownumber()) || "HTGL002".equals(flow.getFlownumber())) {
                    if (JudgeRoleRight.judgeRoleRight("合同管理员",staff.getRoleNames())) {
                        paCount = 0;
                    }
                    pageInfo.setTlist(tblCyhwUnitMapper.selectUnitListByPageInfo(pageInfo, staff.getCurrentOrg().getOrgid().toString(), staff.getStaffid().toString(), paCount));
                    pageInfo.setTotalRecord(tblCyhwUnitMapper.selectUnitCountByPageInfo(pageInfo, staff.getCurrentOrg().getOrgid().toString(), staff.getStaffid().toString(), paCount));
                }
                if ("HTGL007".equals(flow.getFlownumber())) {
                    if (JudgeRoleRight.judgeRoleRight("合同范本管理人员",staff.getRoleNames()) || JudgeRoleRight.judgeRoleRight("合同管理员",staff.getRoleNames())) {
                        paCount = 0;
                    }
                    pageInfo.setTlist(tblCyhwUnitMapper.selectUnitListByPageInfo(pageInfo, staff.getCurrentOrg().getOrgid().toString(), staff.getStaffid().toString(), paCount));
                    pageInfo.setTotalRecord(tblCyhwUnitMapper.selectUnitCountByPageInfo(pageInfo, staff.getCurrentOrg().getOrgid().toString(), staff.getStaffid().toString(), paCount));
                }
                
                
                List<TblCyhwUnit> tlist = pageInfo.getTlist();
                for (TblCyhwUnit unit : tlist) {
                    List<TblContractPlannode> planNodeS = contractPlannodeMapper.findPlanNodeListByContractId(unit.getContractid());
                    unit.setPlanNodeList(planNodeS);
                }
                dataMap.put("typeList", typeList);
                dataMap.put("flowId", flowId);
                dataMap.put("pageInfo", pageInfo);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                Integer paCount = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(), staff);
                List<TblContractTypeof> typeList = this.tblContractTypeofMapper.findAllList(staff.getCurrentOrg().getOrgid(), -1);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                cyhwUnit.setFlowid(flow.getFlowid());
                cyhwUnit.setRecordtype(flow.getFlownumber());
                pageInfo.setCondition(cyhwUnit);

                if ("HTGL005".equals(flow.getFlownumber()) || "HTGL002".equals(flow.getFlownumber()) || "HTGL007".equals(flow.getFlownumber())) {
                    if (JudgeRoleRight.judgeRoleRight("合同管理员",staff.getRoleNames())) {
                        paCount = 0;
                    }
                    pageInfo.setTlist(tblCyhwUnitMapper.selectUnitListByPageInfo(pageInfo, staff.getCurrentOrg().getOrgid().toString(), staff.getStaffid().toString(), paCount));
                    pageInfo.setTotalRecord(tblCyhwUnitMapper.selectUnitCountByPageInfo(pageInfo, staff.getCurrentOrg().getOrgid().toString(), staff.getStaffid().toString(), paCount));
                }
                List<TblCyhwUnit> tlist = pageInfo.getTlist();
                for (TblCyhwUnit unit : tlist) {
                    List<TblContractPlannode> planNodeS = contractPlannodeMapper.findPlanNodeListByContractId(unit.getContractid());
                    unit.setPlanNodeList(planNodeS);
                }
                dataMap.put("typeList", typeList);
                dataMap.put("flowId", flowId);
                dataMap.put("pageInfo", pageInfo);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findLedgerListPageInfo(String token, String staffId, String startdate, String enddate, Integer pageNumber, Integer pageSize, TblCyhwUnit unit){
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                Map<String, Object> dataMap = new HashMap<String, Object>(0);
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                List<TblContractTypeof> typeList = this.tblContractTypeofMapper.findAllList(staff.getCurrentOrg().getOrgid(), -1);
                Integer resultCount = tblOrganizationMapper.findCountByUserSjb(staff.getStaffid());
                if (resultCount == 0 && !JudgeRoleRight.judgeRoleRight("合同管理员",staff.getRoleNames())) {
                    unit.setCreateuser(staff.getStaffid());
                }
                Date enddate1 = null;
                if (enddate == null) {
                    enddate1 = new Date();
                } else {
                    enddate1 = DateUtils.parse(enddate, "yyyy-MM-dd");
                }
                Date startdateNew = null;
                if (startdate == null) {
                    Calendar cal = Calendar.getInstance();
                    startdateNew = DateUtils.parse(cal.get(Calendar.YEAR) + "-01-01", "yyyy-MM-dd");
                } else {
                    startdateNew = DateUtils.parse(startdate, "yyyy-MM-dd");
                }
                unit.setEnddate(enddate1);
                unit.setStartdate(startdateNew);
                unit.setOrgid(staff.getCurrentOrg().getOrgid());
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.selectLedgerListPageInfo(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.selectLedgerCountPageIfo(pageInfo));
                dataMap.put("typeList", typeList);
                dataMap.put("pageInfo", pageInfo);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                Map<String, Object> dataMap = new HashMap<String, Object>(0);
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                List<TblContractTypeof> typeList = this.tblContractTypeofMapper.findAllList(staff.getCurrentOrg().getOrgid(), -1);
                Integer resultCount = tblOrganizationMapper.findCountByUserSjb(staff.getStaffid());
                if (resultCount == 0 && !JudgeRoleRight.judgeRoleRight("合同管理员",staff.getRoleNames())) {
                    unit.setCreateuser(staff.getStaffid());
                }
                Date enddate1 = null;
                if (enddate == null) {
                    enddate1 = new Date();
                } else {
                    enddate1 = DateUtils.parse(enddate, "yyyy-MM-dd");
                }
                Date startdateNew = null;
                if (startdate == null) {
                    Calendar cal = Calendar.getInstance();
                    startdateNew = DateUtils.parse(cal.get(Calendar.YEAR) + "-01-01", "yyyy-MM-dd");
                } else {
                    startdateNew = DateUtils.parse(startdate, "yyyy-MM-dd");
                }
                unit.setEnddate(enddate1);
                unit.setStartdate(startdateNew);
                unit.setOrgid(staff.getCurrentOrg().getOrgid());
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.selectLedgerListPageInfo(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.selectLedgerCountPageIfo(pageInfo));
                dataMap.put("typeList", typeList);
                dataMap.put("pageInfo", pageInfo);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public List<TblCyhwUnit> findLedgerListForExport(TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblCyhwUnitMapper.findLedgerListForExport(unit);
        } else {
            return tblCyhwUnitMapper.findLedgerListForExport(unit);
        }
    }

    @Override
    public Map<String, Object> saveCyhwUnit(TblCyhwUnit tcu, String attids, String staffId, String token, String flowId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }

                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                tcu.setRecordtype(flow.getFlownumber());
                tcu.setCreateuser(staff.getStaffid());
                tcu.setOrgid(staff.getCurrentOrg().getOrgid());
                tcu.setFlowid(flow.getFlowid());
                tcu.setCreatetime(new Date());
                if (tcu.getContractid() != null) {
                    //this.tblCyhwUnitMapper.updateCyhwUnit(tcu);
                	if(tcu.getContractchildren() != null && "否".equals(tcu.getContractchildren())) {
                		tcu.setRecordparent(null);
                	}
                    this.tblCyhwUnitMapper.updateByPrimaryKeySelective(tcu);
                    TblCyhwUnit unit = new TblCyhwUnit();
                    unit.setContractid(tcu.getContractid());
                    unit.setContractchildren(tcu.getContractchildren());
                    unit.setRecordparent(tcu.getRecordparent());
                    unit.setFlowid(tcu.getFlowid());
                    unit.setRecordtype(tcu.getRecordtype());
                    this.tblCyhwUnitMapper.updateCyhwUnit(unit);
                } else {
                    // this.tblCyhwUnitMapper.insertCyhwUnit(tcu);
                    tcu.setContractstatus(0);
                    tblCyhwUnitMapper.insertSelective(tcu);
                }
                if (attids != null && !"".equals(attids)) {
                    String[] ids = attids.split(",");
                    for (String id : ids) {
                        this.tblCyhwUnitMapper.insertAttmentRelation(id, tcu.getContractid());
                    }
                }
                resultMap.put("code", "1");
                resultMap.put("msg", "保存成功！");
                resultMap.put("data", tcu);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }

                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                tcu.setRecordtype(flow.getFlownumber());
                tcu.setCreateuser(staff.getStaffid());
                tcu.setOrgid(staff.getCurrentOrg().getOrgid());
                tcu.setFlowid(flow.getFlowid());
                tcu.setContractstatus(0);
                tcu.setCreatetime(new Date());
                if (tcu.getContractid() != null) {
                    //this.tblCyhwUnitMapper.updateCyhwUnit(tcu);
                    this.tblCyhwUnitMapper.updateByPrimaryKeySelective(tcu);
                } else {
                    // this.tblCyhwUnitMapper.insertCyhwUnit(tcu);
                	tcu.setContractstatus(0);
                    tblCyhwUnitMapper.insertSelective(tcu);
                }
                if (attids != null && !"".equals(attids)) {
                    String[] ids = attids.split(",");
                    for (String id : ids) {
                        this.tblCyhwUnitMapper.insertAttmentRelation(id, tcu.getContractid());
                    }
                }
                resultMap.put("code", "1");
                resultMap.put("msg", "保存成功！");
                resultMap.put("data", tcu);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public Integer getStatueById(Integer contractId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblCyhwUnitMapper.selectStatueById(contractId);
        } else {
            return this.tblCyhwUnitMapper.selectStatueById(contractId);
        }
    }


    @Override
    public Map<String, Object> SubmitForApproval(BigDecimal contractId, String token, String staffId, String examination, String flowId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }

                TblCyhwUnit entity = tblCyhwUnitMapper.selectByContractId(contractId);
                if (entity.getContractstatus() != null && entity.getContractstatus() == 1) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程审批中！");
                    return resultMap;
                }
                if (entity.getContractstatus() != null && entity.getContractstatus() == 3) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已通过！");
                    return resultMap;
                }
                if ((entity.getContractstatus() != null && entity.getContractstatus() == 4) || (entity.getContractstatus() != null && entity.getContractstatus() == 5) || (entity.getContractstatus() != null && entity.getContractstatus() == 6)) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已完成！");
                    return resultMap;
                }
                TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);
                entity.setContractstatus(TblCswlManagement.STATE_SP);
                tblCyhwUnitMapper.updateContractStatus(entity);
                List<TblProcessAnalysis> list = this.tblProcessAnalysisMapper.getByFlowSetting(flow.getSettingid());
                HashMap<String, Object> fields = new HashMap<String, Object>();
                if (list != null && list.size() > 0) {
                    for (TblProcessAnalysis tblAnalysis : list) {
                        TblProcessAnalusisUser analysisUser = this.tblProcessAnalusisUserMapper.findOnd(tblAnalysis.getAnalid().toString(), contractId.toString());
                        if (analysisUser == null) {
                            analysisUser = new TblProcessAnalusisUser();
                            analysisUser.setAnalid(tblAnalysis.getAnalid().toString());
                            analysisUser.setFromid(contractId.toString());
                            analysisUser.setSpdate(new Date());
                            if (tblAnalysis.getUserid() != null) {
                                analysisUser.setStaffid(user.getRealname());
                            } else {
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            }
                            this.tblProcessAnalusisUserMapper.insertSetting(analysisUser);
                        }
                        //合同订立流程参数
                        //提交人参数
                        if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("tcuserid")) {
                            fields.put("tcuserid", user.getStaffid().toString());
                            analysisUser.setStaffid(tblAnalysis.getRolename());
                            System.out.println("tcuserid:" + user.getStaffid());
                        } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("bmfzr")) {
                            //部门负责人参数
                            TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                            if (bmfzr == null) {
                                resultMap.put("code", "0");
                                resultMap.put("msg", "经办部门负责人需配置！");
                                return resultMap;
                            }
                            fields.put("bmfzr", bmfzr.getStaffid().toString());
                            System.out.println("bmfzr:" + bmfzr.getStaffid());
                        } else {
                            //除此之外的参数都设置为当前提交人
                            if (tblAnalysis.getUserid() != null && !tblAnalysis.getUserid().equals("")) {
                                fields.put(tblAnalysis.getUserid(), user.getStaffid().toString());
                                System.out.println(tblAnalysis.getUserid() + ":" + user.getStaffid().toString());
                            }
                        }
                    }
                }
                net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(fields);
                Map<String, Object> map = HttpClient.startProcessAll(flow.getSettingid(), jsonObject.toString());
                String object = (String) map.get("result");
                String processInstanceId = (String) map.get("processInstanceId");
                String processDefinitionKey = (String) map.get("processDefinitionKey");
                TblCirculation cir = this.tblCirculationService.saveTblCirculationnew(TblProcessAnalysis.CYHW_TYPE_JJHTJC, entity.getContractno(), entity.getContractname(), TblProcessAnalysis.CYHW_URL_JJHTJC + contractId, user.getStaffid(), processInstanceId, processDefinitionKey, contractId.toString());
                if (object != null && object.equals("true")) {
                    List<TblMyTask> tasks = HttpClient.findByTask("", user.getStaffid().toString(), 1, 10000);
                    if (tasks != null && tasks.size() > 0) {
                        for (TblMyTask task : tasks) {
                            if (task.getProcessInstanceId().equals(processInstanceId)) {
                                Map<String, Object> map1 = HttpClient.handleProcessJson(user.getStaffid().toString(), "通过", task.getTaskId());
                                String result = (String) map1.get("result");
                                if (result != null && result.equals("true")) {
                                    String blande = "";
                                    //查询执行人
                                    String nextapprover = HttpClient.nextapprover(cir.getBusinesskey());
                                    TblProcessAnalysis analysis = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
                                    Integer number = 1;
                                    String usertaskid = analysis.getUsertaskid();
                                    Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
                                    blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
                                    TblProcessAnalysis analysis1 = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
                                    TblProcessAnalusisUser analysisUser = this.tblProcessAnalysisMapper.findOnd(analysis1.getAnalid().toString(), contractId.toString());
                                    task.setFromid(contractId.toString());
                                    task.setApprover(user.getRealname());
                                    task.setUsrid(user.getStaffid().toString());
                                    task.setExamination(examination);
                                    task.setProcessName(flow.getSettingid());
                                    if (user.getTrole() != null && user.getTrole().getRname() != null) {
                                        task.setApprovalrole(user.getTrole().getRname());
                                    }
                                    task.setApprovaldate(new Date());
                                    task.setResult("通过");
                                    task.setCirid(cir.getCyid().toString());
                                    if (nextapprover.contains("bmfzr")) {
                                        TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                        task.setHandle(bmfzr.getRealname());
                                    } else {
                                        task.setHandle(nextapprover);
                                    }
                                    task.setAnalid(analysisUser.getAnalid().toString());
                                    this.tblMytaskMapper.insertMyTaskSetting(task);
                                }
                            }
                        }
                    }
                    resultMap.put("code", "1");
                    resultMap.put("msg", "审批已提交！");
                } else {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程提交失败！");
                    log.error("发送审批失败");
                }
            } catch (Exception e) {
                log.error("发送审批失败");
                e.printStackTrace();
                resultMap.put("code", "0");
                resultMap.put("msg", "流程提交失败！");
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }

                TblCyhwUnit entity = tblCyhwUnitMapper.selectByContractId(contractId);
                if (entity.getContractstatus() != null && entity.getContractstatus() == 1) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程审批中！");
                    return resultMap;
                }
                if (entity.getContractstatus() != null && entity.getContractstatus() == 3) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已通过！");
                    return resultMap;
                }
                if ((entity.getContractstatus() != null && entity.getContractstatus() == 4) || (entity.getContractstatus() != null && entity.getContractstatus() == 5) || (entity.getContractstatus() != null && entity.getContractstatus() == 6)) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已完成！");
                    return resultMap;
                }
                TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);
                entity.setContractstatus(TblCswlManagement.STATE_SP);
                tblCyhwUnitMapper.updateContractStatus(entity);
                List<TblProcessAnalysis> list = this.tblProcessAnalysisMapper.getByFlowSetting(flow.getSettingid());
                HashMap<String, Object> fields = new HashMap<String, Object>();
                if (list != null && list.size() > 0) {
                    for (TblProcessAnalysis tblAnalysis : list) {
                        TblProcessAnalusisUser analysisUser = this.tblProcessAnalusisUserMapper.findOnd(tblAnalysis.getAnalid().toString(), contractId.toString());
                        if (analysisUser == null) {
                            analysisUser = new TblProcessAnalusisUser();
                            analysisUser.setAnalid(tblAnalysis.getAnalid().toString());
                            analysisUser.setFromid(contractId.toString());
                            analysisUser.setSpdate(new Date());
                            if (tblAnalysis.getUserid() != null) {
                                analysisUser.setStaffid(user.getRealname());
                            } else {
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            }
                            this.tblProcessAnalusisUserMapper.insertSetting(analysisUser);
                        }
                        //合同订立流程参数
                        //提交人参数
                        if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("tcuserid")) {
                            fields.put("tcuserid", user.getStaffid().toString());
                            analysisUser.setStaffid(tblAnalysis.getRolename());
                            System.out.println("tcuserid:" + user.getStaffid());
                        } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("bmfzr")) {
                            //部门负责人参数
                            TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                            if (bmfzr == null) {
                                resultMap.put("code", "0");
                                resultMap.put("msg", "经办部门负责人需配置！");
                                return resultMap;
                            }
                            fields.put("bmfzr", bmfzr.getStaffid().toString());
                            System.out.println("bmfzr:" + bmfzr.getStaffid());
                        } else {
                            //除此之外的参数都设置为当前提交人
                            if (tblAnalysis.getUserid() != null && !tblAnalysis.getUserid().equals("")) {
                                fields.put(tblAnalysis.getUserid(), user.getStaffid().toString());
                                System.out.println(tblAnalysis.getUserid() + ":" + user.getStaffid().toString());
                            }
                        }
                    }
                }
                net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(fields);
                Map<String, Object> map = HttpClient.startProcessAll(flow.getSettingid(), jsonObject.toString());
                String object = (String) map.get("result");
                String processInstanceId = (String) map.get("processInstanceId");
                String processDefinitionKey = (String) map.get("processDefinitionKey");
                TblCirculation cir = this.tblCirculationService.saveTblCirculationnew(TblProcessAnalysis.CYHW_TYPE_JJHTJC, entity.getContractno(), entity.getContractname(), TblProcessAnalysis.CYHW_URL_JJHTJC + contractId, user.getStaffid(), processInstanceId, processDefinitionKey, contractId.toString());
                if (object != null && object.equals("true")) {
                    List<TblMyTask> tasks = HttpClient.findByTask("", user.getStaffid().toString(), 1, 3000);
                    if (tasks != null && tasks.size() > 0) {
                        for (TblMyTask task : tasks) {
                            if (task.getProcessInstanceId().equals(processInstanceId)) {
                                Map<String, Object> map1 = HttpClient.handleProcessJson(user.getStaffid().toString(), "通过", task.getTaskId());
                                String result = (String) map1.get("result");
                                if (result != null && result.equals("true")) {
                                    String blande = "";
                                    //查询执行人
                                    String nextapprover = HttpClient.nextapprover(cir.getBusinesskey());
                                    TblProcessAnalysis analysis = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
                                    Integer number = 1;
                                    String usertaskid = analysis.getUsertaskid();
                                    Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
                                    blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
                                    TblProcessAnalysis analysis1 = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
                                    TblProcessAnalusisUser analysisUser = this.tblProcessAnalysisMapper.findOnd(analysis1.getAnalid().toString(), contractId.toString());
                                    task.setFromid(contractId.toString());
                                    task.setApprover(user.getRealname());
                                    task.setUsrid(user.getStaffid().toString());
                                    task.setExamination(examination);
                                    task.setProcessName(flow.getSettingid());
                                    if (user.getTrole() != null && user.getTrole().getRname() != null) {
                                        task.setApprovalrole(user.getTrole().getRname());
                                    }
                                    task.setApprovaldate(new Date());
                                    task.setResult("通过");
                                    task.setCirid(cir.getCyid().toString());
                                    if (nextapprover.contains("bmfzr")) {
                                        TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                        task.setHandle(bmfzr.getRealname());
                                    } else {
                                        task.setHandle(nextapprover);
                                    }
                                    task.setAnalid(analysisUser.getAnalid().toString());
                                    this.tblMytaskMapper.insertMyTaskSetting(task);
                                }
                            }
                        }
                    }
                    resultMap.put("code", "1");
                    resultMap.put("msg", "审批已提交！");
                } else {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程提交失败！");
                    log.error("发送审批失败");
                }
            } catch (Exception e) {
                log.error("发送审批失败");
                e.printStackTrace();
                resultMap.put("code", "0");
                resultMap.put("msg", "流程提交失败！");
            }
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> removeCyhwUnit(Integer contractId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            tblCyhwUnitMapper.deletePlannode(contractId);
            tblCyhwUnitMapper.deleteattachment(contractId);
            tblCyhwUnitMapper.deleteUnitaTT(contractId);
            tblCyhwUnitMapper.deleteInformation(contractId);
            tblCyhwUnitMapper.deleteunit(contractId);
            resultMap.put("code", "0");
            resultMap.put("msg", "删除成功！");
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            tblCyhwUnitMapper.deletePlannode(contractId);
            tblCyhwUnitMapper.deleteattachment(contractId);
            tblCyhwUnitMapper.deleteUnitaTT(contractId);
            tblCyhwUnitMapper.deleteInformation(contractId);
            tblCyhwUnitMapper.deleteunit(contractId);
            resultMap.put("code", "0");
            resultMap.put("msg", "删除成功！");
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> toSptzglInfojc(String contractId, String cyId, String flowId, String token, String staffId) throws Exception {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblCyhwUnit entity = tblCyhwUnitMapper.getCyhwUnitEntity(Integer.parseInt(contractId.toString()));
                TblCirculation cy = this.tblCirculationMapper.selectCiculaInfoById(contractId);

    			List<TblMyTask> tj = tblMytaskMapper.findByObj(contractId, "审查",staff.getStaffid().toString(),"法务");
    			List<TblMyTask> tj2 = tblMytaskMapper.findByObj(contractId, "审查",staff.getStaffid().toString(),"财务");
    			if(tj.size()>0) {
    				dataMap.put("fw", tj.get(0));
    			}
    			if(tj2.size()>0) {
    				dataMap.put("cw", tj2.get(0));
    			}
                
                List<TblMyTask> list = null;
                if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
                    list = HttpClient.findByTask(staff.getTrole().getRname(), staff.getStaffid().toString(), 1, 10000);
                } else {
                    list = HttpClient.findByTask("", staff.getStaffid().toString(), 1, 10000);
                }
                if (list != null && list.size() > 0) {
                    Map<String, Object> map = null;
                    String resultData = null;
                    String[] results = null;
                    for (TblMyTask myTask : list) {
                        if (cy != null && myTask.getProcessInstanceId().equals(cy.getBusinesskey())) {
                            map = HttpClient.lczxProcessJson(myTask.getTaskId());
                            resultData = (String) map.get("data");
                            results = resultData.replace("\"", "").split(",");
                            if (results.length > 0 && !results[0].equals("")) {
                                List<String> stringB = Arrays.asList(results);
                                dataMap.put("results", stringB);
                                dataMap.put("number", stringB.size());
                            } else {
                                dataMap.put("results", null);
                                dataMap.put("number", 0);
                            }
                            dataMap.put("task", myTask);
                            break;
                        }
                    }

                }
                if (flowId == null) {
                    flowId = entity.getFlowid().toString();
                }

                TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);
                dataMap.put("flowname", flow.getFlownumber());
                if ("HTGL005".equals(flow.getFlownumber()) || "HTGL002".equals(flow.getFlownumber())) {
                    TblContractTypeof type = this.tblContractTypeofMapper.findByName(entity.getContracttype(), staff.getCurrentOrg().getOrgid().toString());
                    List<TblContractPlannode> nodeList = this.tblContractPlannodeMapper.findPlanNodeListByContractId(entity.getContractid());
                    dataMap.put("nodeList", nodeList);
                } else {
                    if ("HTGL007".equals(flow.getFlownumber())) {
                        List<TblContractTypeof> typeList = this.tblContractTypeofMapper.findAllList(staff.getCurrentOrg().getOrgid(), -1);
                        dataMap.put("typeList", typeList);
                        List<TblContractPlannode> nodeList = this.tblContractPlannodeMapper.findPlanNodeListByContractId(entity.getContractid());
                        dataMap.put("nodeList", nodeList);
                    }

                }
                dataMap.put("flowid", flowId);
                dataMap.put("cy", cy);
                dataMap.put("tcu", entity);
                if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
                    dataMap.put("rolename", staff.getTrole().getRname());
                }
                dataMap.put("cz", "sp");
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                if (staff == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblCyhwUnit entity = tblCyhwUnitMapper.getCyhwUnitEntity(Integer.parseInt(contractId.toString()));
                TblCirculation cy = this.tblCirculationMapper.selectCiculaInfoById(contractId);

                List<TblMyTask> list = null;
                if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
                    list = HttpClient.findByTask(staff.getTrole().getRname(), staff.getStaffid().toString(), 1, 5000);
                } else {
                    list = HttpClient.findByTask("", staff.getStaffid().toString(), 1, 5000);
                }
                if (list != null && list.size() > 0) {
                    Map<String, Object> map = null;
                    String resultData = null;
                    String[] results = null;
                    for (TblMyTask myTask : list) {
                        if (cy != null && myTask.getProcessInstanceId().equals(cy.getBusinesskey())) {
                            map = HttpClient.lczxProcessJson(myTask.getTaskId());
                            resultData = (String) map.get("data");
                            results = resultData.replace("\"", "").split(",");
                            if (results.length > 0 && !results[0].equals("")) {
                                List<String> stringB = Arrays.asList(results);
                                dataMap.put("results", stringB);
                                dataMap.put("number", stringB.size());
                            } else {
                                dataMap.put("results", null);
                                dataMap.put("number", 0);
                            }
                            dataMap.put("task", myTask);
                            break;
                        }
                    }

                }
                if (flowId == null) {
                    flowId = entity.getFlowid().toString();
                }

                TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);
                dataMap.put("flowname", flow.getFlownumber());
                if ("HTGL005".equals(flow.getFlownumber()) || "HTGL002".equals(flow.getFlownumber())) {
                    TblContractTypeof type = this.tblContractTypeofMapper.findByName(entity.getContracttype(), staff.getCurrentOrg().getOrgid().toString());
                    List<TblContractPlannode> nodeList = this.tblContractPlannodeMapper.findPlanNodeListByContractId(entity.getContractid());
                    dataMap.put("nodeList", nodeList);
                } else {
                    if ("HTGL007".equals(flow.getFlownumber())) {
                        List<TblContractTypeof> typeList = this.tblContractTypeofMapper.findAllList(staff.getCurrentOrg().getOrgid(), -1);
                        dataMap.put("typeList", typeList);
                        List<TblContractPlannode> nodeList = this.tblContractPlannodeMapper.findPlanNodeListByContractId(entity.getContractid());
                        dataMap.put("nodeList", nodeList);
                    }

                }
                dataMap.put("flowid", flowId);
                dataMap.put("cy", cy);
                dataMap.put("tcu", entity);
                if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
                    dataMap.put("rolename", staff.getTrole().getRname());
                }
                dataMap.put("cz", "sp");
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> viewOppsiteActiviti(String contractId,String taskId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblCyhwUnit unit = this.tblCyhwUnitMapper.selectByContractId(new BigDecimal(contractId));
                List<TblMyTask> list = this.tblMytaskMapper.findByLendid(contractId);
                Map<String, Object> dataMap = new HashMap<String, Object>(0);
                dataMap.put("budget", unit);
                dataMap.put("taskList", list);
                dataMap.put("url", HttpClient.jkurl + taskId);
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblCyhwUnit unit = this.tblCyhwUnitMapper.selectByContractId(new BigDecimal(contractId));
                List<TblMyTask> list = this.tblMytaskMapper.findByLendid(contractId);
                Map<String, Object> dataMap = new HashMap<String, Object>(0);
                dataMap.put("budget", unit);
                dataMap.put("taskList", list);
                dataMap.put("url", HttpClient.jkurl + taskId);
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }


    @Override
    public void findPaymentChoiceContract(PageInfo<TblCyhwUnit> pageInfo, TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.selectListByPageInfo(pageInfo, unit));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.selectCountByPageInfoCount(unit));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.selectListByPageInfo(pageInfo, unit));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.selectCountByPageInfoCount(unit));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        }
    }

    @Override
    public TblCyhwUnit getEntity(BigDecimal contractid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblCyhwUnitMapper.selectChangeContractInfo(contractid);
        } else {
            return this.tblCyhwUnitMapper.selectChangeContractInfo(contractid);
        }
    }

    @Override
    public Map<String, Object> findListWindowOpenByPageInfo(Integer pageNumber, Integer pageSize, String recordType, String token, String staffId,String budgetname,String counterpartno) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                if ("HTGL005".equals(recordType) || "HTGL003".equals(recordType) || "HTGL004".equals(recordType) || "HTGL006".equals(recordType)) {
                    PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                    pageInfo.setCurrentPage(pageNumber);
                    pageInfo.setPageSize(pageSize);
                    TblCyhwUnit tcu = new TblCyhwUnit();
                    tcu.setOrgid(user.getCurrentOrg().getOrgid());
                    tcu.setRecordtype(recordType);
                    tcu.setContractstatus(6);
                    tcu.setContractno(counterpartno);
                    tcu.setContractname(budgetname);
                    pageInfo.setCondition(tcu);
                    pageInfo.setTlist(tblCyhwUnitMapper.findListByPageInfo(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    pageInfo.setTotalRecord(tblCyhwUnitMapper.findCountByPageInfoCount(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    resultMap.put("data", pageInfo);
                } else {
                    PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();
                    pageInfo.setCurrentPage(pageNumber);
                    pageInfo.setPageSize(pageSize);
                    TblCyhwProjectbudget tcpb = new TblCyhwProjectbudget();
                    tcpb.setOrgid(user.getCurrentOrg().getOrgid());
                    tcpb.setRecordtype(recordType);
                    tcpb.setInspectionstatus(6);
                    tcpb.setIsblack(2);
                    tcpb.setBudgetname(budgetname);
                    tcpb.setCounterpartno(counterpartno);
                    pageInfo.setCondition(tcpb);
                    pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageInfo(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findCountByPageInfoCount(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    resultMap.put("data", pageInfo);
                }

                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                if ("HTGL005".equals(recordType) || "HTGL003".equals(recordType) || "HTGL004".equals(recordType) || "HTGL006".equals(recordType)) {
                    PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                    pageInfo.setCurrentPage(pageNumber);
                    pageInfo.setPageSize(pageSize);
                    TblCyhwUnit tcu = new TblCyhwUnit();
                    tcu.setOrgid(user.getCurrentOrg().getOrgid());
                    tcu.setRecordtype(recordType);
                    tcu.setContractstatus(6);
                    tcu.setContractno(counterpartno);
                    tcu.setContractname(budgetname);
                    pageInfo.setCondition(tcu);
                    pageInfo.setTlist(tblCyhwUnitMapper.findListByPageInfo(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    pageInfo.setTotalRecord(tblCyhwUnitMapper.findCountByPageInfoCount(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    resultMap.put("data", pageInfo);
                } else {
                    PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();
                    pageInfo.setCurrentPage(pageNumber);
                    pageInfo.setPageSize(pageSize);
                    TblCyhwProjectbudget tcpb = new TblCyhwProjectbudget();
                    tcpb.setOrgid(user.getCurrentOrg().getOrgid());
                    tcpb.setRecordtype(recordType);
                    tcpb.setInspectionstatus(6);
                    tcpb.setIsblack(2);
                    tcpb.setBudgetname(budgetname);
                    tcpb.setCounterpartno(counterpartno);
                    pageInfo.setCondition(tcpb);
                    pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageInfo(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findCountByPageInfoCount(pageInfo, user.getCurrentOrg().getOrgid().toString()));
                    resultMap.put("data", pageInfo);
                }

                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public TblCyhwUnit findContractById(Integer contractId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblCyhwUnitMapper.findContractById(contractId);
        } else {
            return tblCyhwUnitMapper.findContractById(contractId);
        }
    }

    @Override
    public void modifyContractStatus(BigDecimal historyStatus, Integer currentStatus, BigDecimal contractId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblCyhwUnitMapper.updateModifyContractStatus(historyStatus, currentStatus, contractId);
        } else {
            this.tblCyhwUnitMapper.updateModifyContractStatus(historyStatus, currentStatus, contractId);
        }
    }

    @Override
    public void updateModifyContractStatus(BigDecimal hiscontractstatus, BigDecimal hiscontractstatus1, BigDecimal contractid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblCyhwUnitMapper.updateStatus(hiscontractstatus, hiscontractstatus1, contractid);
        } else {
            this.tblCyhwUnitMapper.updateStatus(hiscontractstatus, hiscontractstatus1, contractid);
        }
    }

    @Override
    public Map<String, Object> htglTjsp(BigDecimal contractId, String examination, String token, String staffId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblCyhwUnit entity = tblCyhwUnitMapper.selectByContractId(contractId);
                System.out.println(entity);
                if (entity.getContractstatus() != null && entity.getContractstatus() == 1) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程审批中！");
                    return resultMap;
                }
                if (entity.getContractstatus() != null && entity.getContractstatus() == 3) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已通过！");
                    return resultMap;
                }
                if ((entity.getContractstatus() != null && entity.getContractstatus() == 4) || (entity.getContractstatus() != null && entity.getContractstatus() == 5) || (entity.getContractstatus() != null && entity.getContractstatus() == 6)) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已完成！");
                    return resultMap;
                }
                if (entity.getContractstatus() == 7) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同正在执行中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 8) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已归档！");
                    return resultMap;
                } else if (entity.getContractstatus() == 9) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已暂停！");
                    return resultMap;
                } else if (entity.getContractstatus() == 10) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已变更！");
                    return resultMap;
                } else if (entity.getContractstatus() == 11) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已终止！");
                    return resultMap;
                } else if (entity.getContractstatus() == 12) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同纠纷中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 13) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同协商中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 14) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同诉讼中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 15) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同仲裁中！");
                    return resultMap;
                }

                if (entity.getDescribe() == null || "".equals(entity.getDescribe())) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "请填写合同正文内容！");
                    return resultMap;
                }

                if (entity.getContractplan() != null && "是".equals(entity.getContractplan())) {
                    Integer planCount = this.contractPlannodeMapper.countPlanByContractId(contractId);
                    if (planCount == 0) {
                        resultMap.put("code", "0");
                        resultMap.put("msg", "请填写合同履行计划！");
                        return resultMap;
                    }
                    Integer postCount = this.contractPlannodeMapper.sumPlanPostPoint(contractId);
                    if (postCount != 100 && !"无".equals(entity.getDctype())) {
                        resultMap.put("code", "0");
                        resultMap.put("msg", "合同履行计划收付款比例不符合标准！");
                        return resultMap;
                    }
                }
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblContractTypeof typeof = tblContractTypeofMapper.findByName(entity.getContracttype(), user.getCurrentOrg().getOrgid().toString());

                entity.setContractstatus(TblCswlManagement.STATE_SP);
                tblCyhwUnitMapper.updateContractStatus(entity);
                List<TblProcessAnalysis> list = tblProcessAnalysisMapper.getByFlowSetting(typeof.getSettingid());
                HashMap<String, Object> fields = new HashMap<String, Object>();
                if (list != null && list.size() > 0) {

                    for (TblProcessAnalysis tblAnalysis : list) {
                        TblProcessAnalusisUser analysisUser = tblProcessAnalusisUserMapper.findOnd(tblAnalysis.getAnalid().toString(), contractId.toString());
                        if (analysisUser == null) {
                            analysisUser = new TblProcessAnalusisUser();
                            analysisUser.setAnalid(tblAnalysis.getAnalid().toString());
                            analysisUser.setFromid(contractId.toString());
                            analysisUser.setSpdate(new Date());
                            if (tblAnalysis.getUserid() != null) {
                                analysisUser.setStaffid(user.getRealname());
                            } else {
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            }
                            //合同订立流程参数
                            //提交人参数
                            if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("tcuserid")) {
                                fields.put("tcuserid", user.getStaffid().toString());
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("bmfzr")) {
                                //部门负责人参数
                                TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                if (bmfzr == null) {
                                    resultMap.put("code", "0");
                                    resultMap.put("msg", "经办部门负责人需配置！");
                                    return resultMap;
                                }
                                fields.put("bmfzr", bmfzr.getStaffid().toString());
                                System.out.println("bmfzr:" + bmfzr.getStaffid());
                            } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("fgld")) {
                                //分管领导参数
                                TblStaff fgld = tblStaffMapper.findByStaffFgOrgs(user.getLinkDetp().getOrgid().toString());
                                if (fgld == null) {
                                    resultMap.put("code", "0");
                                    resultMap.put("msg", "分管领导需配置！");
                                    return resultMap;
                                }
                                fields.put("fgld", fgld.getStaffid().toString());
                                System.out.println("fgld:" + fgld.getStaffid());
                            } else {
                                //除此之外的参数都设置为当前提交人
                                if (StrUtil.isNotBlank(tblAnalysis.getUserid())) {
                                    fields.put(tblAnalysis.getUserid(), user.getStaffid().toString());
                                }
                            }
                            tblProcessAnalusisUserMapper.insertSetting(analysisUser);
                        }
                    }
                }
                String contractzd = entity.getContractzd();
                if("3".equals(contractzd) || "2".equals(contractzd)) {
                	fields.put("contractZd", "是");//合同是否重大、重要
                }else {
                	fields.put("contractZd", "否");//合同是否重大、重要
                }
                //是否归属投资类合同
                TblContractTypeof parentType = tblContractTypeofMapper.selectEntityById(typeof.getParentid().toString());
                if(parentType!=null&&"投资类合同".equals(parentType.getTypename())) {
                	fields.put("contractType", "否");//产业投资合同
                }else {
                	fields.put("contractType", "是");//其他合同
                }
                net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(fields);
                //boolean processJson = HttpClient.startProcess(TblAnalysis.process_name,jsonObject.toString());
                Map<String, Object> map = HttpClient.startProcessAll(typeof.getSettingid(), jsonObject.toString());
                String object = (String) map.get("result");
                String processInstanceId = (String) map.get("processInstanceId");
                String processDefinitionKey = (String) map.get("processDefinitionKey");
                TblCirculation cir = tblCirculationService.saveTblCirculationnew(TblProcessAnalysis.CYHW_TYPE_JJHTJC, entity.getContractno(), entity.getContractname(), TblProcessAnalysis.CYHW_URL_JJHTJC + contractId, user.getStaffid(), processInstanceId, processDefinitionKey, contractId.toString());
                if (object != null && object.equals("true")) {
                    List<TblMyTask> tasks = HttpClient.findByTask("", user.getStaffid().toString(), 1, 10000);
                    if (tasks != null && tasks.size() > 0) {
                        for (TblMyTask task : tasks) {
                            if (task.getProcessInstanceId().equals(processInstanceId)) {
                                Map<String, Object> map1 = HttpClient.handleProcessJson(user.getStaffid().toString(), "通过", task.getTaskId());
                                String result = (String) map1.get("result");
                                if (result != null && result.equals("true")) {
                                    String blande = "";
                                    //查询执行人
                                    String nextapprover = HttpClient.nextapprover(cir.getBusinesskey());
                                    TblProcessAnalysis analysis = tblProcessAnalysisMapper.findOndBytakdidstart(blande, typeof.getSettingid());
                                    Integer number = 1;
                                    String usertaskid = analysis.getUsertaskid();
                                    Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
                                    blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
                                    TblProcessAnalysis analysis1 = tblProcessAnalysisMapper.findOndBytakdidstart(blande, typeof.getSettingid());
                                    TblProcessAnalusisUser analysisUser = tblProcessAnalysisMapper.findOnd(analysis1.getAnalid().toString(), contractId.toString());
                                    task.setFromid(contractId.toString());
                                    task.setApprover(user.getRealname());
                                    task.setUsrid(user.getStaffid().toString());
                                    task.setExamination(examination);
                                    task.setProcessName(typeof.getSettingid());
                                    if (user.getTrole() != null && user.getTrole().getRname() != null) {
                                        task.setApprovalrole(user.getTrole().getRname());
                                    }
                                    task.setApprovaldate(new Date());
                                    task.setResult("通过");
                                    task.setCirid(cir.getCyid().toString());
                                    if (nextapprover.contains("bmfzr")) {
                                        TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                        task.setHandle(bmfzr.getRealname());
                                    }else if (nextapprover.contains("fgld")) {
                                    	//分管领导
                                        TblStaff fgld = tblStaffMapper.findByStaffFgOrgs(user.getLinkDetp().getOrgid().toString());
                                        task.setHandle(fgld.getRealname());
                                    } else {
                                        task.setHandle(nextapprover);
                                    }
                                    task.setAnalid(analysisUser.getAnalid().toString());
                                    tblMytaskMapper.insertMyTaskSetting(task);
                                }
                            }
                        }

                    }
                    resultMap.put("code", "1");
                    resultMap.put("msg", "审批已提交！");
                } else {
                    log.error("发送审批失败");
                    resultMap.put("code", "0");
                    resultMap.put("msg", "发送审批失败！");
                }
            } catch (Exception e) {
                log.error("发送审批失败");
                e.printStackTrace();
                resultMap.put("code", "0");
                resultMap.put("msg", "发送审批失败！");
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblCyhwUnit entity = tblCyhwUnitMapper.selectByContractId(contractId);
                System.out.println(entity);
                if (entity.getContractstatus() != null && entity.getContractstatus() == 1) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程审批中！");
                    return resultMap;
                }
                if (entity.getContractstatus() != null && entity.getContractstatus() == 3) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已通过！");
                    return resultMap;
                }
                if ((entity.getContractstatus() != null && entity.getContractstatus() == 4) || (entity.getContractstatus() != null && entity.getContractstatus() == 5) || (entity.getContractstatus() != null && entity.getContractstatus() == 6)) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "流程已完成！");
                    return resultMap;
                }
                if (entity.getContractstatus() == 7) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同正在执行中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 8) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已归档！");
                    return resultMap;
                } else if (entity.getContractstatus() == 9) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已暂停！");
                    return resultMap;
                } else if (entity.getContractstatus() == 10) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已变更！");
                    return resultMap;
                } else if (entity.getContractstatus() == 11) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同已终止！");
                    return resultMap;
                } else if (entity.getContractstatus() == 12) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同纠纷中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 13) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同协商中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 14) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同诉讼中！");
                    return resultMap;
                } else if (entity.getContractstatus() == 15) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "合同仲裁中！");
                    return resultMap;
                }

                if (entity.getDescribe() == null || "".equals(entity.getDescribe())) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "请填写合同正文内容！");
                    return resultMap;
                }

                if (entity.getContractplan() != null && "是".equals(entity.getContractplan())) {
                    Integer planCount = this.contractPlannodeMapper.countPlanByContractId(contractId);
                    if (planCount == 0) {
                        resultMap.put("code", "0");
                        resultMap.put("msg", "请填写合同履行计划！");
                        return resultMap;
                    }
                    Integer postCount = this.contractPlannodeMapper.sumPlanPostPoint(contractId);
                    if (postCount != 100 && !"无".equals(entity.getDctype())) {
                        resultMap.put("code", "0");
                        resultMap.put("msg", "合同履行计划收付款比例不符合标准！");
                        return resultMap;
                    }
                }
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblContractTypeof typeof = tblContractTypeofMapper.findByName(entity.getContracttype(), user.getCurrentOrg().getOrgid().toString());

                entity.setContractstatus(TblCswlManagement.STATE_SP);
                tblCyhwUnitMapper.updateContractStatus(entity);
                List<TblProcessAnalysis> list = tblProcessAnalysisMapper.getByFlowSetting(typeof.getSettingid());
                HashMap<String, Object> fields = new HashMap<String, Object>();
                if (list != null && list.size() > 0) {

                    for (TblProcessAnalysis tblAnalysis : list) {
                        TblProcessAnalusisUser analysisUser = tblProcessAnalusisUserMapper.findOnd(tblAnalysis.getAnalid().toString(), contractId.toString());
                        if (analysisUser == null) {
                            analysisUser = new TblProcessAnalusisUser();
                            analysisUser.setAnalid(tblAnalysis.getAnalid().toString());
                            analysisUser.setFromid(contractId.toString());
                            analysisUser.setSpdate(new Date());
                            if (tblAnalysis.getUserid() != null) {
                                analysisUser.setStaffid(user.getRealname());
                            } else {
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            }
                            //合同订立流程参数
                            //提交人参数
                            if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("tcuserid")) {
                                fields.put("tcuserid", user.getStaffid().toString());
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("bmfzr")) {
                                System.out.println(user.getOrgid() + "========================");
                                //部门负责人参数
                                TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                if (bmfzr == null) {
                                    resultMap.put("code", "0");
                                    resultMap.put("msg", "经办部门负责人需配置！");
                                    return resultMap;
                                }
                                fields.put("bmfzr", bmfzr.getStaffid().toString());
                                System.out.println("bmfzr:" + bmfzr.getStaffid());
                            } else {
                                //除此之外的参数都设置为当前提交人
                                if (StrUtil.isNotBlank(tblAnalysis.getUserid())) {
                                    fields.put(tblAnalysis.getUserid(), user.getStaffid().toString());
                                }
                            }
                            tblProcessAnalusisUserMapper.insertSetting(analysisUser);
                        }
                    }
                }
                net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(fields);
                //boolean processJson = HttpClient.startProcess(TblAnalysis.process_name,jsonObject.toString());
                Map<String, Object> map = HttpClient.startProcessAll(typeof.getSettingid(), jsonObject.toString());
                String object = (String) map.get("result");
                String processInstanceId = (String) map.get("processInstanceId");
                String processDefinitionKey = (String) map.get("processDefinitionKey");
                TblCirculation cir = tblCirculationService.saveTblCirculationnew(TblProcessAnalysis.CYHW_TYPE_JJHTJC, entity.getContractno(), entity.getContractname(), TblProcessAnalysis.CYHW_URL_JJHTJC + contractId, user.getStaffid(), processInstanceId, processDefinitionKey, contractId.toString());
                if (object != null && object.equals("true")) {
                    List<TblMyTask> tasks = HttpClient.findByTask("", user.getStaffid().toString(), 1, 3000);
                    if (tasks != null && tasks.size() > 0) {
                        for (TblMyTask task : tasks) {
                            if (task.getProcessInstanceId().equals(processInstanceId)) {
                                Map<String, Object> map1 = HttpClient.handleProcessJson(user.getStaffid().toString(), "通过", task.getTaskId());
                                String result = (String) map1.get("result");
                                if (result != null && result.equals("true")) {
                                    String blande = "";
                                    //查询执行人
                                    String nextapprover = HttpClient.nextapprover(cir.getBusinesskey());
                                    TblProcessAnalysis analysis = tblProcessAnalysisMapper.findOndBytakdidstart(blande, typeof.getSettingid());
                                    Integer number = 1;
                                    String usertaskid = analysis.getUsertaskid();
                                    Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
                                    blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
                                    TblProcessAnalysis analysis1 = tblProcessAnalysisMapper.findOndBytakdidstart(blande, typeof.getSettingid());
                                    TblProcessAnalusisUser analysisUser = tblProcessAnalysisMapper.findOnd(analysis1.getAnalid().toString(), contractId.toString());
                                    task.setFromid(contractId.toString());
                                    task.setApprover(user.getRealname());
                                    task.setUsrid(user.getStaffid().toString());
                                    task.setExamination(examination);
                                    task.setProcessName(typeof.getSettingid());
                                    if (user.getTrole() != null && user.getTrole().getRname() != null) {
                                        task.setApprovalrole(user.getTrole().getRname());
                                    }
                                    task.setApprovaldate(new Date());
                                    task.setResult("通过");
                                    task.setCirid(cir.getCyid().toString());
                                    if (nextapprover.contains("bmfzr")) {
                                        TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                        task.setHandle(bmfzr.getRealname());
                                    } else {
                                        task.setHandle(nextapprover);
                                    }
                                    task.setAnalid(analysisUser.getAnalid().toString());
                                    tblMytaskMapper.insertMyTaskSetting(task);
                                }
                            }
                        }

                    }
                    resultMap.put("code", "1");
                    resultMap.put("msg", "审批已提交！");
                } else {
                    log.error("发送审批失败");
                    resultMap.put("code", "0");
                    resultMap.put("msg", "发送审批失败！");
                }
            } catch (Exception e) {
                log.error("发送审批失败");
                e.printStackTrace();
                resultMap.put("code", "0");
                resultMap.put("msg", "发送审批失败！");
            }
            return resultMap;
        }
    }

    @Override
    public Map<String,Object> findeContractInfo(BigDecimal flowId, String flowname, Integer contractId, Integer cflag, String token, String staffId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblCyhwUnit tcu = tblCyhwUnitMapper.getCyhwUnitEntity(contractId);
                if (tcu.getRecordparent() != null) {
                    TblCyhwUnit parent = tblCyhwUnitMapper.findContractById(tcu.getRecordparent().intValue());
                    tcu.setParentname(parent.getContractname());
                }

                List<TblContractPlannode> nodeList = this.contractPlannodeMapper.findPlanNodeListByContractId(tcu.getContractid());
                dataMap.put("nodeList", nodeList);
                List<TblContractInformation> informationList = this.tblContractInformationMapper.findInformationListById(tcu.getContractid());
                dataMap.put("informationList", informationList);

                List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningMapper.findFileListByContractId(tcu.getContractid());
                dataMap.put("signingList", signingList);
                List<TblCyhwUnit> parentList = this.tblCyhwUnitMapper.findAllParentList(tcu.getContractid());
                dataMap.put("parentList", parentList);
                if ("收款".equals(tcu.getDctype())) {
                    List<TblContractCollection> colList = this.tblContractCollectionMapper.findcollectionListByContractId(tcu.getContractid());
                    dataMap.put("colList", colList);
                }
                if ("付款".equals(tcu.getDctype())) {
                    List<TblContractPayment> payList = this.tblContractPaymentMapper.findpaymentListByContractId(tcu.getContractid());
                    dataMap.put("payList", payList);
                }
                //List<TblAttachment> attList = this.tblCyhwUnitMapper.findContractSealFileList(user.getCurrentOrg().getOrgid(),contractId);

                List<TblAttachment> attList = this.tblCyhwUnitMapper.findContractSealFileList(user.getCurrentOrg().getOrgid(), contractId);

                TblContractTypeof type = this.tblContractTypeofMapper.findByName(tcu.getContracttype(), user.getCurrentOrg().getOrgid().toString());


                if ("default".equals(type.getPageurl())) {
                    dataMap.put("type", "/nbkz/cyhw/cyhwUnitDetail");
                } else {
                    dataMap.put("type", type.getPageurl());
                }
                dataMap.put("tcu", tcu);
                dataMap.put("flowid", flowId);
                dataMap.put("attList", attList);
                dataMap.put("flowname", flowname);
                dataMap.put("cz", "view");
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblCyhwUnit tcu = null;
                tcu = tblCyhwUnitMapper.findeContractInfo(contractId, flowname);
                if (tcu == null || (cflag != null && cflag == 1)) {
                    tcu = tblCyhwUnitMapper.getCyhwUnitEntity(contractId);
                }
                if (tcu.getRecordparent() != null) {
                    TblCyhwUnit parent = tblCyhwUnitMapper.findContractById(tcu.getRecordparent().intValue());
                    tcu.setParentname(parent.getContractname());
                }

                List<TblContractPlannode> nodeList = this.contractPlannodeMapper.findPlanNodeListByContractId(tcu.getContractid());
                dataMap.put("nodeList", nodeList);
                List<TblContractInformation> informationList = this.tblContractInformationMapper.findInformationListById(tcu.getContractid());
                dataMap.put("informationList", informationList);

                List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningMapper.findFileListByContractId(tcu.getContractid());
                dataMap.put("signingList", signingList);
                List<TblCyhwUnit> parentList = this.tblCyhwUnitMapper.findAllParentList(tcu.getContractid());
                dataMap.put("parentList", parentList);
                if ("收款".equals(tcu.getDctype())) {
                    List<TblContractCollection> colList = this.tblContractCollectionMapper.findcollectionListByContractId(tcu.getContractid());
                    dataMap.put("colList", colList);
                }
                if ("付款".equals(tcu.getDctype())) {
                    List<TblContractPayment> payList = this.tblContractPaymentMapper.findpaymentListByContractId(tcu.getContractid());
                    dataMap.put("payList", payList);
                }
                //List<TblAttachment> attList = this.tblCyhwUnitMapper.findContractSealFileList(user.getCurrentOrg().getOrgid(),contractId);

                List<TblAttachment> attList = this.tblCyhwUnitMapper.findContractSealFileList(user.getCurrentOrg().getOrgid(), contractId);

                TblContractTypeof type = this.tblContractTypeofMapper.findByName(tcu.getContracttype(), user.getCurrentOrg().getOrgid().toString());


                if ("default".equals(type.getPageurl())) {
                    dataMap.put("type", "/nbkz/cyhw/cyhwUnitDetail");
                } else {
                    dataMap.put("type", type.getPageurl());
                }
                dataMap.put("tcu", tcu);
                dataMap.put("flowid", flowId);
                dataMap.put("attList", attList);
                dataMap.put("flowname", flowname);
                dataMap.put("cz", "view");
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findContractSealList(Integer pageNumber,Integer pageSize,String cateId, String flowid, String isFlowdb, String choose, String token, String staffId, TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user1 = DealUserToken.parseUserToken(token);
                if (user1 == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                //TblStaff user = this.tblStaffMapper.findByStaffid(user1.getStaffid().toString());
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowid);
                dataMap.put("flow", flow);
                Integer result = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(), user1);

                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setPageSize(pageSize);
                pageInfo.setCurrentPage(pageNumber);
                unit.setRecordtype("HTGL003");
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user1.getCurrentOrg().getOrgid());

                if (!"".equals(choose) && choose != null) {
                    unit.setContractname(choose);
                }
                if (result <= 0) {
                    unit.setJbstaff(user1.getStaffid());
                }
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findContractSealList(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findCountContractSealList(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("processName", flow.getSettingid());
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                dataMap.put("flow", flow);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user1 = DealUserToken.parseUserToken(token);
                if (user1 == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                //TblStaff user = this.tblStaffMapper.findByStaffid(user1.getStaffid().toString());
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowid);
                dataMap.put("flow", flow);
                Integer result = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(), user1);

                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setPageSize(pageSize);
                pageInfo.setCurrentPage(pageNumber);
                unit.setRecordtype("HTGL003");
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user1.getCurrentOrg().getOrgid());

                if (!"".equals(choose) && choose != null) {
                    unit.setContractname(choose);
                }
                if (result <= 0) {
                    unit.setJbstaff(user1.getStaffid());
                }
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findContractSealList(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findCountContractSealList(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("processName", flow.getSettingid());
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                dataMap.put("flow", flow);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }

    }

    @Override
    public void modifyContrac(BigDecimal hiscontractstatus, BigDecimal currentStatus, BigDecimal contractid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblCyhwUnitMapper.updateModifyContrac(hiscontractstatus, currentStatus, contractid);
        } else {
            this.tblCyhwUnitMapper.updateModifyContrac(hiscontractstatus, currentStatus, contractid);
        }
    }

    @Override
    public void modifyContract(BigDecimal hiscontractstatus, BigDecimal hiscontractstatus1, BigDecimal contractid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblCyhwUnitMapper.modifyContract(hiscontractstatus, hiscontractstatus1, contractid);
        } else {
            this.tblCyhwUnitMapper.modifyContract(hiscontractstatus, hiscontractstatus1, contractid);
        }
    }

    @Override
    public Map<String, Object> findeFilContractList(Integer pageNumber, Integer pageSize, String flowid, String token, String staffId, TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findByFlowid(flowid);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setContractstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findeFilContractList(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findeCountFilContractList(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("processName", flow.getSettingid());
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                dataMap.put("flow", flow);
                dataMap.put("currentUser", user);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findByFlowid(flowid);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setContractstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findeFilContractList(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findeCountFilContractList(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("processName", flow.getSettingid());
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                dataMap.put("flow", flow);
                dataMap.put("currentUser", user);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> updBasicUnitinspectionStatue(Integer contractId,String flowname) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblCyhwUnit tcu = tblCyhwUnitMapper.findContractById(contractId);
                if ("HTGL005".equals(flowname)) {
                    if (tcu.getRecordparent() != null) {
                        TblCyhwUnit tcu2 = tblCyhwUnitMapper.findContractById(Integer.parseInt(tcu.getRecordparent().toString()));                
                        		//修改原我的合同状态
                        this.tblCyhwUnitMapper.modifyContractStatus(tcu2.getContractid(), tcu2.getHiscontractstatus() == null ? "7" : tcu2.getHiscontractstatus().toString());
                    }
                    //删除我的变更中的数据
                    tblCyhwUnitService.removeCyhwUnit(contractId);
                }
                resultMap.put("code", "1");
                resultMap.put("msg", "已撤回!");
                return resultMap;
            } catch (Exception e) {
                e.printStackTrace();
                resultMap.put("code", "0");
                resultMap.put("msg", "撤回失败");
                return resultMap;
            }
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblCyhwUnit tcu = tblCyhwUnitMapper.findContractById(contractId);
                if ("HTGL005".equals(flowname)) {
                    if (tcu.getRecordparent() != null) {
                        TblCyhwUnit tcu2 = tblCyhwUnitMapper.findContractByParentId(tcu.getRecordparent());
                        //修改原我的合同状态
                        this.tblCyhwUnitMapper.modifyContractStatus(tcu2.getContractid(), tcu2.getHiscontractstatus() == null ? "7" : tcu2.getHiscontractstatus().toString());
                    }
                    //删除我的变更中的数据
                    tblCyhwUnitService.removeCyhwUnit(contractId);
                }
                resultMap.put("code", "1");
                resultMap.put("msg", "已撤回!");
                return resultMap;
            } catch (Exception e) {
                e.printStackTrace();
                resultMap.put("code", "0");
                resultMap.put("msg", "撤回失败");
                return resultMap;
            }
        }
    }

    @Override
    public Map<String, Object> updateContractStatus(String contractId, String status) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            this.tblCyhwUnitMapper.modifyContractStatus(new BigDecimal(contractId), status);
            resultMap.put("code", "1");
            resultMap.put("msg", "归档成功");
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            this.tblCyhwUnitMapper.modifyContractStatus(new BigDecimal(contractId), status);
            resultMap.put("code", "1");
            resultMap.put("msg", "归档成功");
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findeContractListByContractStaff(String flowId, Integer pageNumber, Integer pageSize, String token, String staffId, TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setContractstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findeContractListByContractStaff(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findeCountContractListByContractStaff(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("flowname", flow.getFlownumber());
                dataMap.put("flow", flow);
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setContractstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findeContractListByContractStaff(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findeCountContractListByContractStaff(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("flowname", flow.getFlownumber());
                dataMap.put("flow", flow);
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findeContractListPerformanceTracking(String flowId, Integer pageNumber, Integer pageSize, String token, String staffId, TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setContractstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findeContractListPerformanceTracking(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findeCountContractListPerformanceTracking(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("flowname", flow.getFlownumber());
                dataMap.put("flow", flow);
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                unit.setFlowid(flow.getFlowid());
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setContractstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findeContractListPerformanceTracking(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findeCountContractListPerformanceTracking(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("flowname", flow.getFlownumber());
                dataMap.put("flow", flow);
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findFulfillmentContract(String flowId, Integer pageNumber, Integer pageSize, String token, String staffId, TblCyhwUnit unit) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            TblStaffUtil user = null;
            try {
                user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setJbstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findFulfillmentContract(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findCountFulfillmentContract(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("flow", flow);
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            TblStaffUtil user = null;
            try {
                user = DealUserToken.parseUserToken(token);
                if (user == null) {
                    resultMap.put("code", "0");
                    resultMap.put("msg", "用户已失效！");
                    return resultMap;
                }
                TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
                PageInfo<TblCyhwUnit> pageInfo = new PageInfo<TblCyhwUnit>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                unit.setOrgid(user.getCurrentOrg().getOrgid());
                unit.setJbstaff(user.getStaffid());
                pageInfo.setCondition(unit);
                pageInfo.setTlist(tblCyhwUnitMapper.findFulfillmentContract(pageInfo));
                pageInfo.setTotalRecord(tblCyhwUnitMapper.findCountFulfillmentContract(pageInfo));
                dataMap.put("pageInfo", pageInfo);
                dataMap.put("flow", flow);
                dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_mainck" : flow.getFlowmappingurl()));
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
                resultMap.put("data", dataMap);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return resultMap;
        }
    }

    @Resource
    private TblContractAppendixsigningMapper appendixsigningMapper;

    @Override
    public Map<String, Object> contractExcuteContractId(String contractId, String status) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                Integer fileCount = this.appendixsigningMapper.selectCountByContractId(new BigDecimal(contractId),0);
                if (fileCount == 0 ) {
                    resultMap.put("code", "1");
                    resultMap.put("msg", "未上传对方签署文件，无法执行！");
                    return resultMap;
                } else {
                    this.tblCyhwUnitMapper.modifyContractStatus(new BigDecimal(contractId), "7");
                    resultMap.put("code", "1");
                    resultMap.put("msg", "成功");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                Integer fileCount = this.appendixsigningMapper.selectCountByContractId(new BigDecimal(contractId),0);
                if (fileCount == 0) {
                    resultMap.put("code", "1");
                    resultMap.put("msg", "未上传对方签署文件，无法执行！");
                    return resultMap;
                } else {
                    this.tblCyhwUnitMapper.modifyContractStatus(new BigDecimal(contractId), "7");
                    resultMap.put("code", "1");
                    resultMap.put("msg", "成功");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }

    }

    @Override
    public Map<String, Object> modifyContractStatus(String contractId, Integer goalStatus) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                if (goalStatus == 7) {
                	Integer fileCount = this.appendixsigningMapper.selectCountByContractId(new BigDecimal(contractId),0);
                    if (fileCount == 0) {
                        this.tblCyhwUnitMapper.updaContractStatus(contractId, 6);
                        resultMap.put("code", "1");
                        return resultMap;
                    }
                }
                if (goalStatus == 10) {
                    copeContractInfoForBinageng(contractId);
                }
                this.tblCyhwUnitMapper.updaContractStatus(contractId, goalStatus);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                if (goalStatus == 7) {
                	Integer fileCount = this.appendixsigningMapper.selectCountByContractId(new BigDecimal(contractId),0);
                    if (fileCount == 0) {
                        this.tblCyhwUnitMapper.updaContractStatus(contractId, 6);
                        resultMap.put("code", "1");
                        return resultMap;
                    }
                }
                if (goalStatus == 10) {
                    copeContractInfoForBinageng(contractId);
                }
                this.tblCyhwUnitMapper.updaContractStatus(contractId, goalStatus);
                resultMap.put("code", "1");
                resultMap.put("msg", "访问接口成功");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

    public void copeContractInfoForBinageng(String contractId) throws Exception {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblCyhwUnit unit = this.tblCyhwUnitMapper.getCyhwUnitEntity(Integer.parseInt(contractId));
            List<TblContractPlannode> nodeList = tblContractPlannodeMapper.getListPlannodeForBianGeng(contractId);
            TblCyhwUnit newunit = new TblCyhwUnit();
            newunit.setCreateuser(unit.getCreateuser());
            newunit.setOrgid(unit.getOrgid());
            newunit.setCreatetime(new Date());
            newunit.setEnddate(unit.getEnddate());
            newunit.setStartdate(unit.getStartdate());
            newunit.setContractdept(unit.getContractdept());
            newunit.setLinkdept(unit.getLinkdept());
            newunit.setContractstaff(unit.getContractstaff());
            newunit.setContractxdfxinfo(unit.getContractxdfxinfo());
            newunit.setRecordparent(unit.getRecordparent());
            newunit.setJbstaff(unit.getJbstaff());
            newunit.setJbdept(unit.getJbdept());
            newunit.setJbunit(unit.getJbdept());
            newunit.setZxunit(unit.getZxunit());
            newunit.setContractdept(unit.getContractdept());
            newunit.setFlowid(unit.getFlowid());
            newunit.setContractstatus(0);
            newunit.setContractmoney(unit.getContractmoney());
            newunit.setContractname(unit.getContractname());
            newunit.setCounterpartbank(unit.getCounterpartbank());
            /*String writen = this.tblOrganizationMapper.selectWrittenDeptByOrgId(unit.getOrgid());
            String writenDept = this.tblOrganizationMapper.selectWrittenDeptByUserId(unit.getCreateuser());
            String year = DateUtil.parseDate(new Date(), "yyyy");
            String contractno = writen+writenDept+"["+year+"]";
            String no = this.tblCyhwUnitMapper.selectCountByContractNo(contractno,contractno+"%","HTGL002");
			if(no != null) {
				 no = no.replace(contractno, "");
			}else {
				no = "0";
			}
            contractno += (Integer.parseInt(no)+1);*/
            String no = "HTDL" + DateUtils.dateToUnixTimestamp();
            newunit.setContractno(no);
            newunit.setDescribe(unit.getDescribe());
            newunit.setMomoconcat(unit.getMomoconcat());
            newunit.setRiskcontrol(unit.getRiskcontrol());
            newunit.setContractdatetype(unit.getContractdatetype());
            newunit.setContracttype(unit.getContracttype());
            newunit.setContractxz(unit.getContractxz());
            newunit.setContractitem(unit.getContractitem());
            newunit.setDctype(unit.getDctype());
            newunit.setContractzd(unit.getContractzd());
            newunit.setContractchildren(unit.getContractchildren());
            newunit.setTopic(unit.getTopic());
            newunit.setTopicid(unit.getTopicid());
            newunit.setContractbd(unit.getContractbd());
            newunit.setMoneytype(unit.getMoneytype());
            newunit.setHzsumowing(unit.getHzsumowing());
            newunit.setJijiatype(unit.getJijiatype());
            newunit.setContractplan(unit.getContractplan());
            newunit.setRecordtype("HTGL005");
            newunit.setRecordparent(unit.getContractid());
            tblCyhwUnitMapper.insertSelective(newunit);
            TblContractPlannode node = null;
            TblContractSpnode spNode = null;
            List<TblContractInformation> inforMationList = tblContractInformationMapper.getInfomationList(contractId);
            TblContractInformation newInfo = null;
            Iterator var10 = inforMationList.iterator();
            TblContractInformation info = null;
            while (var10.hasNext()) {
                info = (TblContractInformation) var10.next();
                newInfo = new TblContractInformation();
                newInfo.setInfono(info.getInfono());
                newInfo.setInfoname(info.getInfoname());
                newInfo.setInfotype(info.getInfotype());
                newInfo.setInfoxh(info.getInfoxh());
                newInfo.setInfoorg(info.getInfoorg());
                newInfo.setInfoprice(info.getInfoprice());
                newInfo.setInfonum(info.getInfonum());
                newInfo.setInfodesc(info.getInfodesc());
                newInfo.setInfomomo(info.getInfomomo());
                newInfo.setInfopinpai(info.getInfopinpai());
                newInfo.setInfostartdate(info.getInfostartdate());
                newInfo.setInfoenddate(info.getInfoenddate());
                newInfo.setProjectid(newunit.getContractid());
                this.tblContractInformationMapper.saveContractInfoMation(newInfo);
            }
            var10 = nodeList.iterator();
            while (true) {
                TblContractPlannode oldNode;
                do {
                    if (!var10.hasNext()) {
                        return;
                    }
                    oldNode = (TblContractPlannode) var10.next();
                } while (oldNode.getPlannodestatus() != null && oldNode.getPlannodestatus().intValue() == 2);

                node = new TblContractPlannode();
                node.setNodecontent(oldNode.getNodecontent());
                node.setPlanenddate(oldNode.getPlanenddate());
                node.setPlanstartdate(oldNode.getPlanstartdate());
                node.setNodepost(oldNode.getNodepost());
                node.setNodeplanpaydate(oldNode.getNodeplanpaydate());
                node.setProjectid(newunit.getContractid());
                node.setDispatchstaff(oldNode.getDispatchstaff());
                node.setNodemoney(oldNode.getNodemoney());
                node.setDispatchdept(oldNode.getDispatchdept());
                node.setPlannodestatus(null);
                this.tblContractPlannodeMapper.saveContractPlannode(node);
            }
        } else {
            TblCyhwUnit unit = this.tblCyhwUnitMapper.getCyhwUnitEntity(Integer.parseInt(contractId));
            List<TblContractPlannode> nodeList = tblContractPlannodeMapper.getListPlannode(contractId);
            TblCyhwUnit newunit = new TblCyhwUnit();
            newunit.setCreateuser(unit.getCreateuser());
            newunit.setOrgid(unit.getOrgid());
            newunit.setCreatetime(new Date());
            newunit.setEnddate(unit.getEnddate());
            newunit.setStartdate(unit.getStartdate());
            newunit.setContractdept(unit.getContractdept());
            newunit.setLinkdept(unit.getLinkdept());
            newunit.setContractstaff(unit.getContractstaff());
            newunit.setContractxdfxinfo(unit.getContractxdfxinfo());
            newunit.setRecordparent(unit.getRecordparent());
            newunit.setJbstaff(unit.getJbstaff());
            newunit.setJbdept(unit.getJbdept());
            newunit.setJbunit(unit.getJbdept());
            newunit.setZxunit(unit.getZxunit());
            newunit.setContractdept(unit.getContractdept());
            newunit.setFlowid(unit.getFlowid());
            newunit.setContractstatus(0);
            newunit.setContractmoney(unit.getContractmoney());
            newunit.setContractname(unit.getContractname());
            /*String writen = this.tblOrganizationMapper.selectWrittenDeptByOrgId(unit.getOrgid());
            String writenDept = this.tblOrganizationMapper.selectWrittenDeptByUserId(unit.getCreateuser());
            String year = DateUtil.parseDate(new Date(), "yyyy");
            String contractno = writen+writenDept+"["+year+"]";
            String no = this.tblCyhwUnitMapper.selectCountByContractNo(contractno,contractno+"%","HTGL002");
			if(no != null) {
				 no = no.replace(contractno, "");
			}else {
				no = "0";
			}
            contractno += (Integer.parseInt(no)+1);*/
            String no = "HTDL" + DateUtils.dateToUnixTimestamp();
            newunit.setContractno(no);
            newunit.setDescribe(unit.getDescribe());
            newunit.setMomoconcat(unit.getMomoconcat());
            newunit.setRiskcontrol(unit.getRiskcontrol());
            newunit.setContractdatetype(unit.getContractdatetype());
            newunit.setContracttype(unit.getContracttype());
            newunit.setContractxz(unit.getContractxz());
            newunit.setContractitem(unit.getContractitem());
            newunit.setDctype(unit.getDctype());
            newunit.setContractzd(unit.getContractzd());
            newunit.setContractchildren(unit.getContractchildren());
            newunit.setTopic(unit.getTopic());
            newunit.setTopicid(unit.getTopicid());
            newunit.setContractbd(unit.getContractbd());
            newunit.setMoneytype(unit.getMoneytype());
            newunit.setHzsumowing(unit.getHzsumowing());
            newunit.setJijiatype(unit.getJijiatype());
            newunit.setContractplan(unit.getContractplan());
            newunit.setRecordtype("HTGL005");
            this.tblCyhwUnitMapper.insertCyhwUnit(newunit);
            TblContractPlannode node = null;
            TblContractSpnode spNode = null;
            List<TblContractInformation> inforMationList = tblContractInformationMapper.getInfomationList(contractId);
            TblContractInformation newInfo = null;
            Iterator var10 = inforMationList.iterator();
            while (var10.hasNext()) {
                TblContractInformation info = (TblContractInformation) var10.next();
                newInfo = new TblContractInformation();
                newInfo.setInfono(info.getInfono());
                newInfo.setInfoname(info.getInfoname());
                newInfo.setInfotype(info.getInfotype());
                newInfo.setInfoxh(info.getInfoxh());
                newInfo.setInfoorg(info.getInfoorg());
                newInfo.setInfoprice(info.getInfoprice());
                newInfo.setInfonum(info.getInfonum());
                newInfo.setInfodesc(info.getInfodesc());
                newInfo.setInfomomo(info.getInfomomo());
                newInfo.setInfopinpai(info.getInfopinpai());
                newInfo.setInfostartdate(info.getInfostartdate());
                newInfo.setInfoenddate(info.getInfoenddate());
                newInfo.setProjectid(info.getProjectid());
                this.tblContractInformationMapper.saveContractInfoMation(newInfo);
            }
            var10 = nodeList.iterator();
            while (true) {
                TblContractPlannode oldNode;
                do {
                    if (!var10.hasNext()) {
                        return;
                    }
                    oldNode = (TblContractPlannode) var10.next();
                } while (oldNode.getPlannodestatus() != null && oldNode.getPlannodestatus().intValue() == 2);

                node = new TblContractPlannode();
                node.setNodecontent(oldNode.getNodecontent());
                node.setPlanenddate(oldNode.getPlanenddate());
                node.setPlanstartdate(oldNode.getPlanstartdate());
                node.setNodepost(oldNode.getNodepost());
                node.setNodeplanpaydate(oldNode.getNodeplanpaydate());
                node.setProjectid(oldNode.getProjectid());
                node.setDispatchstaff(oldNode.getDispatchstaff());
                node.setDispatchdept(oldNode.getDispatchdept());
                node.setPlannodestatus(null);
                node.setNodemoney(oldNode.getNodemoney());
                this.tblContractPlannodeMapper.saveContractPlannode(node);
            }
        }
    }


    @Override
    public void findLegalContractListByPageInfo(PageInfo<TblCyhwUnit> pageInfo, TblCyhwUnit tcu) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findLegalContractListByPageInfo(pageInfo, tcu));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findLegalContractListByPageInfoCount(tcu));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } else {

        }
    }

    @Override
    public void saveCyhwUnitTcu(TblCyhwUnit tcu) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblCyhwUnitMapper.insertCyhwUnit(tcu);
        } else {
            this.tblCyhwUnitMapper.insertCyhwUnit(tcu);
        }
    }

    @Override
    public void updateTcu(TblCyhwUnit tcu) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblCyhwUnitMapper.updateCyhwUnit(tcu);
        } else {
            this.tblCyhwUnitMapper.updateCyhwUnit(tcu);
        }
    }
    public void updateCyhwUnitNoDescrpib(TblCyhwUnit tcu) {
    	if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
    		this.tblCyhwUnitMapper.updateCyhwUnitNoDescrpib(tcu);
    	} else {
    		this.tblCyhwUnitMapper.updateCyhwUnitNoDescrpib(tcu);
    	}
    }

    @Override
    public Map<String, Object> findListByXdf(PageInfo<TblCyhwUnit> pageInfo, String budgetid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListByXdf(pageInfo, budgetid));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListByXdfCount(budgetid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListByXdf(pageInfo, budgetid));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListByXdfCount(budgetid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findListContractBiangengBypage(PageInfo<TblCyhwUnit> pageInfo, BigDecimal orgid, String userid, boolean findByModuel) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListContractBiangengBypage(pageInfo, orgid, userid, findByModuel));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListContractBiangengBypageCount(orgid, userid, findByModuel));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListContractBiangengBypage(pageInfo, orgid, userid, findByModuel));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListContractBiangengBypageCount(orgid, userid, findByModuel));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        }
    }

    @Override
    public void findListByPageInfo(PageInfo<TblCyhwUnit> pageInfo, BigDecimal orgid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListByPage(pageInfo, orgid));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListByPageCount(orgid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListByPage(pageInfo, orgid));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListByPageCount(orgid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        }
    }

    @Override
    public void findListByPage(PageInfo<TblCyhwUnit> pageInfo, String userid, BigDecimal orgid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListByPa(pageInfo, userid, orgid));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListByPaCount(userid, orgid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findListByPa(pageInfo, userid, orgid));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findListByPaCount(userid, orgid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        }
    }

    @Override
    public List<TblCyhwUnit> findListBy(Integer budgetid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            List<TblCyhwUnit> selectAllParentInfoList = this.tblCyhwUnitMapper.selectAllParentInfoList(budgetid);
            return selectAllParentInfoList;
        } else {
            List<TblCyhwUnit> selectAllParentInfoList = this.tblCyhwUnitMapper.selectAllParentInfoList(budgetid);
            return selectAllParentInfoList;
        }
    }

    @Override
    public List<TblCyhwUnit> findContractTemp(String token, String contractType) throws Exception {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            return this.tblCyhwUnitMapper.selectContractTemp(staff.getCurrentOrg().getOrgid(), contractType);
        } else {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            return this.tblCyhwUnitMapper.selectContractTemp(staff.getCurrentOrg().getOrgid(), contractType);
        }
    }

    @Override
    public Map<String, Object> findContractDes(String budgetId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            String descirp = this.tblCyhwUnitMapper.findContractDes(budgetId);
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", descirp);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            String descirp = this.tblCyhwUnitMapper.findContractDes(budgetId);
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", descirp);
            return resultMap;
        }
    }

    @Override
    public TblCyhwUnit findContractMoneyById(BigDecimal contractid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblCyhwUnitMapper.selectByContractId(contractid);
        } else {
            return this.tblCyhwUnitMapper.selectByContractId(contractid);
        }
    }

//    @Override
//    public Map<String, Object> findByUnitID(Integer contractid) {
//        Map<String, Object> resultMap = new HashMap<String, Object>(0);
//        TblCyhwUnit tblCyhwUnit = tblCyhwUnitMapper.selectByPrimaryKey(contractid);
//        resultMap.put("code", "1");
//        resultMap.put("msg", "访问接口成功");
//        resultMap.put("data", tblCyhwUnit);
//        return resultMap;
//    }


    @Override
        public void findCollectionChoiceContract (PageInfo < TblCyhwUnit > pageInfo, BigDecimal pid, String
        contractno, String contractname){
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findCollectionChoiceContractPid(pageInfo, pid, contractno, contractname));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findCollectionChoiceContractPidCount(pid, contractno, contractname));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblCyhwUnitMapper.findCollectionChoiceContractPid(pageInfo, pid, contractno, contractname));
            pageInfo.setTotalRecord(tblCyhwUnitMapper.findCollectionChoiceContractPidCount(pid, contractno, contractname));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        }
        }

    @Override
	public Map<String, Object> oppsiteInfogetList(String startDate, String orgid) throws Exception {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            // TODO Auto-generated method stub
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                JSONObject obj = new JSONObject();
                List<JSONObject> list = tblCyhwUnitMapper.getList(orgid, startDate);
                List<JSONObject> list2 = new ArrayList();
                for (JSONObject j : list) {
                    JSONObject i = new JSONObject();
                    Double CONTRACTMONEY = Double.parseDouble(j.get("CONTRACTMONEY").toString());
                    Double paymoney = 0.0;
                    if (j.get("PAYMONEY") != null) {
                        paymoney = Double.parseDouble(j.get("PAYMONEY").toString());
                    }
                    Double nopaymoney = CONTRACTMONEY - paymoney;
                    i.put("nopaymoney", nopaymoney);
                    i.put("contractid", j.get("CONTRACTID") != null ? j.get("CONTRACTID").toString() : "");
                    i.put("contractname", j.get("CONTRACTNAME") != null ? j.get("CONTRACTNAME").toString() : "");
                    i.put("contractno", j.get("CONTRACTNO") != null ? j.get("CONTRACTNO").toString() : "");
                    i.put("contractmoney", j.get("CONTRACTMONEY") != null ? j.get("CONTRACTMONEY").toString() : "");
                    i.put("contractitem", j.get("CONTRACTITEM") != null ? j.get("CONTRACTITEM").toString() : "");
   				    i.put("fundpoolname", j.get("FUNDPOOLNAME")!=null?j.get("FUNDPOOLNAME").toString():"");
                    i.put("contracttype", j.get("CONTRACTTYPE") != null ? j.get("CONTRACTTYPE").toString() : "");
                    i.put("recordConcatname", j.get("RECORDCONCATNAME") != null ? j.get("RECORDCONCATNAME").toString() : "");
                    i.put("moneytype", j.get("MONEYTYPE") != null ? j.get("MONEYTYPE").toString() : "");
                    i.put("startdate", j.get("STARTDATE") != null ? j.get("STARTDATE").toString() : "");
                    i.put("enddate", j.get("ENDDATE") != null ? j.get("ENDDATE").toString() : "");
                    list2.add(i);
                }
                obj.put("tlist", list2);
                resultMap.put("code", "0");
                resultMap.put("msg", "访问成功");
                resultMap.put("data", obj);
            } catch (Exception e) {
                // TODO: handle exception
                resultMap.put("code", "1");
                resultMap.put("msg", "访问失败！");
            }
            return resultMap;
        } else {
            // TODO Auto-generated method stub
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                JSONObject obj = new JSONObject();
                List<JSONObject> list = tblCyhwUnitMapper.getList(orgid, startDate);
                List<JSONObject> list2 = new ArrayList();
                for (JSONObject j : list) {
                    JSONObject i = new JSONObject();
                    Double CONTRACTMONEY = Double.parseDouble(j.get("CONTRACTMONEY").toString());
                    Double paymoney = 0.0;
                    if (j.get("PAYMONEY") != null) {
                        paymoney = Double.parseDouble(j.get("PAYMONEY").toString());
                    }
                    Double nopaymoney = CONTRACTMONEY - paymoney;
                    i.put("nopaymoney", nopaymoney);
                    i.put("contractid", j.get("CONTRACTID") != null ? j.get("CONTRACTID").toString() : "");
                    i.put("contractname", j.get("CONTRACTNAME") != null ? j.get("CONTRACTNAME").toString() : "");
                    i.put("contractno", j.get("CONTRACTNO") != null ? j.get("CONTRACTNO").toString() : "");
                    i.put("contractmoney", j.get("CONTRACTMONEY") != null ? j.get("CONTRACTMONEY").toString() : "");
                    i.put("contractitem", j.get("CONTRACTITEM") != null ? j.get("CONTRACTITEM").toString() : "");
                    i.put("contracttype", j.get("CONTRACTTYPE") != null ? j.get("CONTRACTTYPE").toString() : "");
                    i.put("recordConcatname", j.get("RECORDCONCATNAME") != null ? j.get("RECORDCONCATNAME").toString() : "");
                    i.put("moneytype", j.get("MONEYTYPE") != null ? j.get("MONEYTYPE").toString() : "");
                    i.put("startdate", j.get("STARTDATE") != null ? j.get("STARTDATE").toString() : "");
                    i.put("enddate", j.get("ENDDATE") != null ? j.get("ENDDATE").toString() : "");
                    list2.add(i);
                }
                obj.put("tlist", list2);
                resultMap.put("code", "0");
                resultMap.put("msg", "访问成功");
                resultMap.put("data", obj);
            } catch (Exception e) {
                // TODO: handle exception
                resultMap.put("code", "1");
                resultMap.put("msg", "访问失败！");
            }
            return resultMap;
        }
	}

	@Override
	public Map<String, Object> contractFjInfo(Integer contractid) throws Exception {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            // TODO Auto-generated method stub
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                JSONObject obj = new JSONObject();
                List<TblAttachment> list = tblCyhwUnitMapper.findeFileInfo(contractid);
                List<JSONObject> list2 = new ArrayList();
                for (TblAttachment t : list) {
                    JSONObject o = new JSONObject();
                    o.put("singingId", t.getAttid());
                    o.put("singingName", t.getAttname());
                    o.put("singingSize", t.getAttsize());
                    byte[] inputStream = FtpUtil.getInputStreamByOa(t.getAttpath(), t.getAttname());
                    o.put("fileStream", inputStream);
                    list2.add(o);
                }
                obj.put("tlist", list2);
                resultMap.put("code", "0");
                resultMap.put("msg", "访问成功");
                resultMap.put("data", obj);
            } catch (Exception e) {
                // TODO: handle exception
                resultMap.put("code", "1");
                resultMap.put("msg", "访问失败！");
            }
            return resultMap;
        } else {
            // TODO Auto-generated method stub
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                JSONObject obj = new JSONObject();
                List<TblAttachment> list = tblCyhwUnitMapper.findeFileInfo(contractid);
                List<JSONObject> list2 = new ArrayList();
                for (TblAttachment t : list) {
                    JSONObject o = new JSONObject();
                    o.put("singingId", t.getAttid());
                    o.put("singingName", t.getAttname());
                    o.put("singingSize", t.getAttsize());
                    byte[] inputStream = FtpUtil.getInputStreamByOa(t.getAttpath(), t.getAttname());
                    o.put("fileStream", inputStream);
                    list2.add(o);
                }
                obj.put("tlist", list2);
                resultMap.put("code", "0");
                resultMap.put("msg", "访问成功");
                resultMap.put("data", obj);
            } catch (Exception e) {
                // TODO: handle exception
                resultMap.put("code", "1");
                resultMap.put("msg", "访问失败！");
            }
            return resultMap;
        }
	}
	
	
	@Override
	public JsonBean checkLendStatus(String token, String contractId) throws Exception {
		TblStaffUtil user = DealUserToken.parseUserToken(token);
		if (user == null) {
			return ResponseFormat.retParam(1, 20006, null);
		}
		
		try {
			TblContractLend lend = this.tblContractLendMapper.selectLendRecord(user.getStaffid().toString(), contractId);
			//无记录,可以创建
			if(null==lend) {
				return ResponseFormat.retParam(1, 30003, null);
			}
			//是否有借阅记录，且归还日期在今天后
			int compareDateWithNow = DateUtils.compareDateWithNow(lend.getReturndate());
			if(compareDateWithNow==1 && lend.getLendstatus()==6) {
				return ResponseFormat.retParam(2, 200, null);
			}
			return ResponseFormat.retParam(1, 30004, null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseFormat.retParam(2, 200, null);
	}
	

	@Override
	public void findMySqlCollectionChoiceContract(PageInfo<TblCyhwUnitMySql> pageInfo, BigDecimal pid,
			String contractno, String contractname) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Map<String, Object> findMySqlListContractBiangengBypageInfo(String token, String flowId, String staffId,
			Integer pageNumber, Integer pageSize, TblCyhwUnitMySql cyhwUnit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findMySqlLedgerListPageInfo(String token, String staffId, String startdate,
			String enddate, Integer pageNumber, Integer pageSize, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<TblCyhwUnitMySql> findMySqlLedgerListForExport(TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> saveMySqlCyhwUnit(TblCyhwUnitMySql tcu, String attids, String staffId, String token,
			String flowId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void findMySqlPaymentChoiceContract(PageInfo<TblCyhwUnitMySql> pageInfo, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public TblCyhwUnitMySql getMySqlEntity(BigDecimal contractid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TblCyhwUnitMySql findContractByMySqlId(Integer contractId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findMySqlContractSealList(Integer pageNumber, Integer pageSize, String cateId,
			String flowid, String isFlowdb, String choose, String token, String staffId, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findeMySqlFilContractList(Integer pageNumber, Integer pageSize, String flowid,
			String token, String staffId, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findeMySqlContractListByContractStaff(String flowId, Integer pageNumber,
			Integer pageSize, String token, String staffId, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findeMySqlContractListPerformanceTracking(String flowId, Integer pageNumber,
			Integer pageSize, String token, String staffId, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findMySqlFulfillmentContract(String flowId, Integer pageNumber, Integer pageSize,
			String token, String staffId, TblCyhwUnitMySql unit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void findMySqlLegalContractListByPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, TblCyhwUnitMySql tcu) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveMySqlCyhwUnitTcu(TblCyhwUnitMySql tcu) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateMySqlTcu(TblCyhwUnitMySql tcu) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Map<String, Object> findListByMySqlXdf(PageInfo<TblCyhwUnitMySql> pageInfo, String budgetid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> findListContractBiangengByMySqlpage(PageInfo<TblCyhwUnitMySql> pageInfo,
			BigDecimal orgid, String userid, boolean findByModuel) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void findListByMySqlPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, BigDecimal orgid) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void findListByMySqlPage(PageInfo<TblCyhwUnitMySql> pageInfo, String userid, BigDecimal orgid) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<TblCyhwUnitMySql> findListByMySql(Integer budgetid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<TblCyhwUnitMySql> findMySqlContractTemp(String token, String contractType) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TblCyhwUnitMySql findContractMoneyByMySqlId(BigDecimal contractid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String findecontracFlowIdByContractId(Integer contractid) throws Exception {
		return this.tblCyhwUnitMapper.selectContracFlowIdByContractId(contractid);
	}

}
